package com.qidian.by.goods.repository;

import com.qidian.by.goods.service.RabbitTemplateClientService;
import com.qidian.by.goods.service.impl.RabbitTemplateClientServiceImpl;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.amqp.RabbitTemplateConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Properties;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-05-18 08:39
 **/
@Repository
public class FanoutRabbitRepository {
    @Resource
    private Properties fanoutExchangeProperty;


//    @Bean
//    @Qualifier("protoRabbitTemplate")
//    @Primary
//    @Scope("prototype")
//    public RabbitTemplate getProtoRabbitTemplate(RabbitTemplateConfigurer configurer, ConnectionFactory connectionFactory) {
//        RabbitTemplate template = new RabbitTemplate();
//        configurer.configure(template, connectionFactory);
//        template.setMandatory(true);
//        return template;
//    }

    @Bean
    @Qualifier("itemRabbitTemplateClientService")
    public RabbitTemplateClientService itemRabbitTemplateClientService() {
        System.out.println("创建了对象");
        return new RabbitTemplateClientServiceImpl(fanoutExchangeProperty.getProperty("item-queue"));
    }

    @Bean
    @Qualifier("searchRabbitTemplateClientService")
    public RabbitTemplateClientService searchRabbitTemplateClientService() {
        System.out.println("创建了对象");
        return new RabbitTemplateClientServiceImpl(fanoutExchangeProperty.getProperty("search-queue"));
    }
}
